package pl.task;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.EditText;

public class TaskEntityEditActivity extends Activity
{
    private static final String TAG = "TaskEntityEditActivity";

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    {
        boolean result = false;

        Log.d(TAG, "onKeyDown " + keyCode);
        if (keyCode == KeyEvent.KEYCODE_BACK)
        {
            result = true;

            final Intent resultIntent = new Intent();
            resultIntent.putExtra("_ID", getIntent().getLongExtra("_ID", -1));

            resultIntent.putExtra("nazwa", ((EditText) findViewById(R.id.editTaskNazwa)).getText().toString());
            resultIntent.putExtra("opis", ((EditText) findViewById(R.id.editTaskOpis)).getText().toString());

            setResult(RESULT_OK, resultIntent);
            finish();
        }

        return result;
    }

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        Log.d(TAG, "onCreate");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.task_edit);

        ((EditText) findViewById(R.id.editTaskNazwa)).setText(getIntent().getStringExtra("nazwa"));
        ((EditText) findViewById(R.id.editTaskOpis)).setText(getIntent().getStringExtra("opis"));
    }
}
